# -*- coding:utf-8 -*-
import logging

import allure


from Enterprise_wechat_app.po.base_page import BasePage
from Enterprise_wechat_app.po import utils


class EditMemberPage(BasePage):
    # 读取yaml文件数据
    get_datas = utils.yml_data()
    def edit_member_success(self,name,phone):
        """
        编辑资料后保存成功断言
        :return:
        """
        # 姓名
        self.find_xpath_send(self.get_datas.get('get_name'),name)
        # 选择性别
        self.find_xpath_click(self.get_datas.get('get_sex'))
        # 选择男
        self.find_xpath_click(self.get_datas.get('select_man'))
        # 手机号
        self.find_id_send(self.get_datas.get('get_phone'),phone)
        # 滑动查询"保存"元素,点击
        self.find_uiautomator_click(self.get_datas.get("get_save"))
        # 获取保存成功提示，特殊控件Toast
        # result=self.find_xpath(self.get_datas.get('get_Toast')).text #这种方式会报错，待查原因
        result = self.driver.find_element_by_xpath( '//*[@class="android.widget.Toast"]').text
        logging.info(f'提示：{result}')
        # 保存截图到指定路径
        self.driver.save_screenshot(r'../testcase/screenshot/保存成功_截图.png')
        # allure报告截图
        allure.attach(self.driver.get_screenshot_as_png(),"保存成功_截图",allure.attachment_type.PNG)
        return result

    def edit_member_to_AddMenberPage(self,name,phone):
        """
        编辑资料后跳转到添加成员界面
        :return:
        """
        driver = self.driver
        # 姓名
        self.find_xpath_send(self.get_datas.get('get_name'), name)
        # 选择性别
        self.find_xpath_click(self.get_datas.get('get_sex'))
        # 选择男
        self.find_xpath_click(self.get_datas.get('select_man'))
        # 手机号
        self.find_id_send(self.get_datas.get('get_phone'), phone)
        # 滑动查询"保存"元素,点击
        self.find_uiautomator_click(self.get_datas.get("get_save"))
        # 保存截图到指定路径
        self.driver.save_screenshot(r'../testcase/screenshot/保存成功_截图.png')
        # allure报告截图
        allure.attach(self.driver.get_screenshot_as_png(), "保存成功_截图", allure.attachment_type.PNG)
        from Enterprise_wechat_app.po.add_member_page import AddMenberPage
        return AddMenberPage(self.driver)

    def delete_member_success(self,name):
        """
        点击删除成员成功断言
        :return:
        """
        # 滑动查询"删除成员"元素,点击
        self.find_uiautomator_click(self.get_datas.get('del_member'))
        # 点击确定
        self.find_id_click(self.get_datas.get('ensure_button'))
        # 获取添加客户文本
        result=self.find_uiautomator(self.get_datas.get('get_member')).text
        logging.info(f'获取到：{result}')
        # 保存截图到指定路径
        self.driver.save_screenshot(r'../testcase/screenshot/删除成功_截图.png')
        # allure报告截图
        allure.attach(self.driver.get_screenshot_as_png(),"删除成功_截图",allure.attachment_type.PNG)
        return result